home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / os2 / ext2_200.zip / EXT2_SRC.ZIP / 32BITS / EXT2-OS2 / UTIL / ATTR.C next >
C/C++ Source or Header  |  1996-09-17  |  3KB  |  103 lines

  1. //
  2. // $Header: D:/32bits/ext2-os2/util/RCS/attr.c,v 1.1 1996/08/26 19:04:53 Willm Exp Willm $
  3. //
  4.  
  5. // Linux ext2 file system driver for OS/2 2.x and WARP - Allows OS/2 to     
  6. // access your Linux ext2fs partitions as normal drive letters.
  7. // Copyright (C) 1995, 1996 Matthieu WILLM 
  8. //
  9. // This program is free software; you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation; either version 2 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program; if not, write to the Free Software
  21. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. #ifdef __IBMC__
  23. #pragma strings(readonly)
  24. #endif
  25.  
  26. #define INCL_DOSERRORS
  27. #define INCL_NOPMAPI
  28. #include <os2.h>        // From the "Developer Connection Device Driver Kit" version 2.0
  29.  
  30. #include <os2/types.h>
  31. #include <os2/os2proto.h>
  32. #include <linux/fs.h>
  33. #include <linux/stat.h>
  34.  
  35. #define FILE_NONFAT     0x0040        // File is non 8.3 compliant
  36.  
  37. #ifndef MINIFSD
  38. //
  39. // Maps DOS SHRA attributes to Linux rwxrwxrwx file modes
  40. //
  41. // Handles only DOS SHRA attributes
  42. //     A - ignored
  43. //    S - ignored
  44. //    H - ignored
  45. //    R - S_IWUSR, S_IWGRP and S_IWOTH cleared
  46. //     !R - S_IWUSR set
  47. void DOS_To_Linux_Attrs(struct inode *inode, unsigned short DOS_attrs) {
  48.     if (DOS_attrs & FILE_READONLY) {
  49.         /*
  50.          * Set file to read only if not already
  51.          */
  52.         if (((inode->i_mode & S_IWUSR)) ||
  53.             ((inode->i_mode & S_IWGRP)) ||
  54.             ((inode->i_mode & S_IWOTH))) {
  55.             inode->i_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  56.         inode->i_dirt  = 1;
  57.         }
  58.     } else {
  59.         /*
  60.          * Set file to read write if not already
  61.          */
  62.         if (!(((inode->i_mode & S_IWUSR)) ||
  63.               ((inode->i_mode & S_IWGRP)) ||
  64.               ((inode->i_mode & S_IWOTH)))) {
  65.             inode->i_mode |= S_IWUSR;
  66.         inode->i_dirt  = 1;    
  67.         }
  68.     }
  69. }
  70. #endif /* #ifndef MINIFSD */
  71.  
  72. //
  73. // Maps Linux file modes to DOS DSHRA attributes
  74. //
  75. unsigned short Linux_To_DOS_Attrs(struct inode *inode, char *component) {
  76.     unsigned short mapped;
  77.  
  78.     mapped = FILE_NORMAL;
  79.  
  80.     if ((S_ISLNK(inode->i_mode))  ||
  81.         (S_ISBLK(inode->i_mode))  ||
  82.         (S_ISCHR(inode->i_mode))  ||
  83.         (S_ISFIFO(inode->i_mode)) ||
  84.         (S_ISSOCK(inode->i_mode))) {
  85.         mapped |= FILE_SYSTEM;     /*** UNIXish special files are seen as SYSTEM files ***/
  86.     } /* endif */
  87.  
  88.     if (S_ISDIR(inode->i_mode)) {
  89.         mapped |= FILE_DIRECTORY;
  90.     } /* endif */
  91.  
  92.     if ((!(inode->i_mode & S_IWUSR)) && 
  93.         (!(inode->i_mode & S_IWGRP)) &&
  94.         (!(inode->i_mode & S_IWOTH))) {
  95.         mapped |= FILE_READONLY;
  96.     }
  97.  
  98.     if (!isfat(component)) {
  99.         mapped |= FILE_NONFAT;        // Non 8.3 file name
  100.     }
  101.  
  102.     return mapped;
  103. }